package ivo.listener;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

public class SessionCounter implements HttpSessionListener {

	private Logger logger = Logger.getLogger(SessionCounter.class);

	/* Session创建事件 */
	public void sessionCreated(HttpSessionEvent se) {
		String ip = "";
		HttpServletRequest request = ServletActionContext.getRequest();
		// 获取访问用户客户端IP
		ip = request.getRemoteAddr();
		logger.info("Connection Started! SessionID:" + se.getSession().getId()
				+ ",IP:" + ip);

	}

	/* Session失效事件 */
	public void sessionDestroyed(HttpSessionEvent se) {

		logger.info("Connection Ended! SessionID:" + se.getSession().getId());

	}
}